home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0038_Adding to Program Manager.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-11-22  |  2.3 KB  |  77 lines

  1.  
  2. {Here is what's left from what I got from borland some time ago.
  3. The DDEClient is a component you drop on the form (System, DdeClientItem). }
  4.  
  5.  
  6. Var Macro : String;
  7. Var Cmd: array[0..255] of Char;
  8. NewPrg,Desc : String;
  9. Begin
  10.     { Create the group, does nothing if it existst } 
  11.     Name := 'StartUp';
  12.     Macro := Format('[CreateGroup(%s)]', [Name]) + #13#10;
  13.     StrPCopy (Cmd, Macro);
  14.     DDEClient.OpenLink;
  15.     if not DDEClient.ExecuteMacro(Cmd, False) then
  16.       MessageDlg(<ErrorMsg>, mtInformation, [mbOK], 0);
  17.  
  18.     { Then you add you program }
  19.     NewPrg := 'C:\HELLO.EXE';      {Full path of the program you}
  20.     Desc := 'Say Hello';           {Description that appears under the icon|    
  21.  
  22.     Macro := '[AddItem('+NewPrg+','+Desc+')]'+ #13#10;
  23.     StrPCopy (Cmd, Macro);
  24.     if not f1_.DDEClient.ExecuteMacro(Cmd, False) then
  25.       MessageDlg(<errorMsg>,mtInformation, [mbOK], 0);
  26.  
  27.     { To make sure the group is saved }
  28.  
  29.     StrPCopy (Cmd,'[ShowGroup(nonexist,1)]');
  30.     DDEClient.ExecuteMacro(Cmd, False);
  31.  
  32.  
  33.      { Now... this part doesn't work and I don't know why }   
  34.      { Anybody who knows why is welcome }
  35.  
  36.     StrPCopy (Cmd,'[reload()]');
  37.     DDEClient.ExecuteMacro(Cmd, False);
  38.  
  39.  
  40.      { and close the link }
  41.     DDEClient.CloseLink;
  42. End;
  43.  
  44. A procedure to get all groups from the program manager using a DDEclientconv:
  45. {This example needs a listbox called AllGroups}
  46.  
  47. procedure GetGroups(Sender: TObject);
  48. var
  49. Thedata: pchar;     {pchar that holds the groups}
  50. dat: char;        {used to process each group}
  51. charcount: word;        
  52.  Theitem,theline:string;
  53.  
  54. begin
  55. {get allgroups items}
  56. charcount:=0;
  57. TheData:= DDEClientConv2.RequestData('Groups');
  58. theline:='';
  59. repeat
  60.        application.processmessages;
  61.        dat:=Thedata[charcount];{get character from the Thedata}
  62.        if (dat=chr(10)) {or (dat=chr(13))} then
  63.           begin
  64.                 while Pos(char(10), Theline) > 0 do
  65.                     delete(Theline,pos(char(10),Theline),1);
  66.                 while Pos(char(13), Theline) > 0 do
  67.                     delete(Theline,pos(char(13),Theline),1);
  68.               If theline='' then continue;
  69.               allgroups.items.add(theline); {Allgroups is a LISTBOX}
  70.               theline:='';
  71.           end;
  72.        Theline:=theline+dat;
  73.        inc(charcount);
  74. until charcount>=strlen(Thedata);
  75. strdispose(Thedata);
  76. end;
  77.